package com.example.graduation.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.graduation.entity.Hot;
import com.example.graduation.form.UpdateHotForm;
import com.example.graduation.service.HotService;
import com.example.graduation.util.R;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author xyc
 * @since 2022-02-11
 */
@RestController
@RequestMapping("/hot")
public class HotController {

    @Resource
    private HotService hotService;


    /**
     * @api {POST} /hot/updateHot 更新热度
     * @apiVersion 1.0.0
     * @apiGroup HotController
     * @apiName updateHot
     * @apiParam (请求体) {Number} goodsId 商品id
     * @apiParam (请求体) {String} goodsName 商品名称
     * @apiParamExample 请求体示例
     * {"goodsId":8577,"goodsName":"RFWz8EM"}
     * @apiSuccess (响应结果) {Object} response
     * @apiSuccessExample 响应结果示例
     * {}
     */
    @PostMapping("/updateHot")
    @ResponseBody
    public R updateHot(@RequestBody UpdateHotForm form) {
        hotService.updateHot(form.getGoodsId(), form.getGoodsName());
        return R.ok("更新热度成功");
    }


    /**
     * @api {POST} /hot/searchHotList 查询热度前八榜单
     * @apiVersion 1.0.0
     * @apiGroup HotController
     * @apiName searchHotList
     * @apiSuccess (响应结果) {Object} response
     * @apiSuccessExample 响应结果示例
     * {}
     */
    @PostMapping("/searchHotList")
    @ResponseBody
    public R searchHotList() {
        Page<Hot> hotPage = hotService.searchHotList();
        return R.ok("查询热度榜单成功").put("page", hotPage);
    }

}

